﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MaxLeaf.Common;
using MaxLeaf.DB;
using System.Data;
using MySql.Data.MySqlClient;

namespace MaxLeaf.DAL.K2W
{
    /*
        Insert into k3_department (Fitemid,Db_id,department_name,parent_id) 
         * values(Fitemid,db_id,部门名称,parent_id)
        */
    /// <summary>
    /// 部门
    /// </summary>
    public class t_departmentDAL : BaseDAL
    {
        public t_departmentDAL()
            : base()
        {
            strTableName = "k3_department";
            strOrgTableName = "t_department";

            strKeyFieldName = "Fitemid";
            strOrgKeyFieldName = "FItemID";

            strFieldNames = "Db_id,department_name,parent_id,is_delete";
            strOrgFieldNames = "0,1,2";
        }
        protected override void DAL_GetFieldData(DBAccess dbOrgK3Con, DBAccess dbDestWebReadCon, DBAccess dbDestWebWriteCon, string strFieldName, string strOrgFieldName, DataRow drOrgData, DataRow drDestData)
        {
            if (strFieldName.Equals("Db_id", StringComparison.InvariantCultureIgnoreCase))
            {
                KeyValuePair<string, IDataParameter[]> kvp = dbDestWebReadCon.CreateCondParam(new Dictionary<string, object>() { { "dbname", dbOrgK3Con.ServerDBName }  });
                string strSql = string.Format("select db_id from k3_db_main Where {0}", kvp.Key);
                drDestData[strFieldName] = dbDestWebReadCon.GetValue(strSql,kvp.Value );
            }
            else if (strFieldName.Equals("department_name", StringComparison.InvariantCultureIgnoreCase))
            {
                drDestData[strFieldName] = drOrgData["FName"];
            }
            else if (strFieldName.Equals("parent_id", StringComparison.InvariantCultureIgnoreCase))
            {
                drDestData[strFieldName] = drOrgData["FParentid"];
            }
            else if (strFieldName.Equals("is_delete", StringComparison.InvariantCultureIgnoreCase))
            {
                drDestData[strFieldName] = CvtFunc.ToBoolean(drOrgData["Fdeleted"]);
            }
        }
    }
}